package echat.future.cn.echat.my.view;

import android.app.Dialog;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.my.api.UserApi;
import echat.future.cn.echat.my.bean.UserBean;
import echat.future.cn.echat.my.utils.HttpUtilsRequst;
import echat.future.cn.echat.my.utils.MeHelper;
import echat.future.cn.echat.my.utils.UserHelper;
import echat.future.cn.echat.my.weight.Navagation.AdapterNavagation;
import echat.future.cn.echat.my.weight.Navagation.IBaseNavagation;
import echat.future.cn.echat.my.weight.dialog.StringDialog;
import lumingweihua.future.cn.baselibgxh.base.MyApplication;
import lumingweihua.future.cn.baselibgxh.network.AbstractRequest;
import lumingweihua.future.cn.baselibgxh.network.BeanRequest;
import lumingweihua.future.cn.baselibgxh.network.JsonElementRequest;
import lumingweihua.future.cn.baselibgxh.network.ReqTag;
import lumingweihua.future.cn.baselibgxh.network.entity.DefaultMamahaoServerError;
import lumingweihua.future.cn.baselibgxh.network.entity.MamaHaoServerError;
import lumingweihua.future.cn.baselibgxh.utils.Constant;

/**
 * Created by Administrator on 2018/10/1.
 */

public class EditeAuthInfo2Activity extends lumingweihua.future.cn.baselibgxh.base.BaseActivity {

    private Dialog heightDialog;

    private Dialog weightDialog;

    private List<String> selectTags = new ArrayList<>();

    TextView height;
    TextView weight;
    TextView xingxiang;
    LinearLayout ll_tag;
    TextView tag1;
    TextView tag2;
    @Override
    public void initView() {
        setContentView(R.layout.activity_edite_auth_info2);
        initTitleBar("编辑资料", Constant.DEFAULT_LEFT_BACK,"");
        height = findViewById(R.id.height);
        weight = findViewById(R.id.weight);
        xingxiang = findViewById(R.id.xingxiang);
        ll_tag = findViewById(R.id.ll_tag);
        tag1 = findViewById(R.id.tag1);
        tag2 = findViewById(R.id.tag2);

        findViewById(R.id.height).setOnClickListener(this);
        findViewById(R.id.weight).setOnClickListener(this);
        findViewById(R.id.xingxiang).setOnClickListener(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void processClick(View v) {
        switch (v.getId()) {
            case R.id.height:
                //身高
                showHeightDialog();
                break;
            case R.id.weight:
                //体重
                showWeight();
                break;
            case R.id.xingxiang:
                //形象
                startActivityForResult(new Intent(this, SetTagActivity.class), 10);
                break;

            default:
                break;
        }
    }

    private void showHeightDialog() {
        if (heightDialog == null) {
            heightDialog = new StringDialog.Builder(this)
                    .title("选择身高")
                    .datas(MeHelper.getHeight())
                    .comfirmListener(title -> {
                        height.setText(title);
                    })
                    .builder();
        }
        heightDialog.show();
    }


    private void showWeight() {
        if (weightDialog == null) {
            weightDialog = new StringDialog.Builder(this)
                    .title("选择体重").datas(MeHelper.getWeight())
                    .comfirmListener(title -> {
                        weight.setText(title);
                            }
                    )
                    .builder();
        }
        weightDialog.show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 10 && resultCode == RESULT_OK) {
            showTags(data.getStringArrayListExtra("data"),data.getStringExtra("ids"));
        }

    }

    private void showTags(List<String> tags, String ids) {
        xingxiang.setVisibility(View.GONE);
        ll_tag.setVisibility(View.VISIBLE);
        ll_tag.setContentDescription(ids==null?"":ids);
        selectTags.clear();
        selectTags.addAll(tags);
        tag1.setText(tags.get(0));
        tag2.setText(tags.get(1));
    }

    private final int REQUEST_DATAS = 6;

    public void requestEmoney() {
        // TODO Auto-generated method stub
        JsonElementRequest<DefaultMamahaoServerError> req = new JsonElementRequest<DefaultMamahaoServerError>(
                context, "/api/user/ope_video", this);

        req.setParam("token", UserHelper.getToken());

        addRequestQueue(req, REQUEST_DATAS);

    }

    @Override
    protected void onResponseSuccess(ReqTag tag, Object data) {
        super.onResponseSuccess(tag, data);
        switch (tag.getReqId()) {
            case REQUEST_DATAS:
                break;

            default:
                break;
        }
    }

    @Override
    protected void onResponseFailure(ReqTag tag, MamaHaoServerError error, AbstractRequest.MamaHaoError clientError) {
        super.onResponseFailure(tag, error, clientError);
    }

}
